Skip to main content

Cloud Integration

Requirements

To connect the board to AWS, a provisioning is required. After the provisioning is completed, verify that the device appears in AWS by going to AWS Console -> IoTCore -> All Devices-> Things.

Certain policies have to be enabled for the MQTT connection. In the things section, click on the thing, go to Certificates and click on the certificate in the table. The policies for the certificate will then appear. Select the zt_policy -> Edit active version -> Add new statement. Append the following entry:

  • Policy effect: Allow
  • Policy action: iot:Publish
  • Policy resource: arn:aws:iot:<the-region-you-are-working-in>:<your-account-ID>:topic/sensorData

Remember to check the box setting the edited version as the active version for the policy.

After doing so, your policies should look like this:

Cloud Services

This project requires some services in AWS to manage the data received before displaying it on a webpage:

CloudFormation

AWS CloudFormation allows for creating a Stack of services, meaning that one just needs to specify the different requirements for each service in a template file before they are generated automatically. This makes it easy to create a suite of services for a new instance of a project. The template written for this stack can be downloaded here.

With this template, head to AWS Console -> CloudFormation -> Create Stack, and then choose the Template is ready option, and when specifying the template choose the Upload a template file option. Upload the template and press Next. You should see something similar to this:

Define a Stack Name, change the different parameters according to what you like, and then press Next. You will then arrive on the Configure stack options page, which you can skip (if you don't have any specifications). Now review that everything is as you want on the Review Page. You need to select the checkbox that tells you that AWS Cloudformation might create IAM resources with custom names. Press Submit and you are ready to go!

IAM

The Identity and Access Management (IAM) is a service that allows you to manage the permission within your AWS account. For this project, the IAM service will be used to create a role with several permission policies associated, mainly:

  • Scanning & querying data from the DynamoDB tables that will be created.
  • Creating a log group for the lambda functions.
  • Inserting items into the DynamoDB tables.

IoT Core

The IoT Core is an AWS service that allows you to manage the IoT devices (also known as Things) connected to your AWS account. This is the service used to communicate with our AVR-IoT Cellular Mini by receiving the MQTT messages sent from the device, and forwarding them to DynamoDB. This is achieved using Rules.

Rules can be triggered on specific events (in this case when something is published to our sensorData topic). The rules have an SQL statement associated with them. The SQL statements allow for selecting the different attributes in the messages sent from the AVR-IoT Cellular Mini.

DynamoDB

The DynamoDB service is a Key-Value NoSQL database, which is highly scalable. This project uses 2 tables:

  • Sensor data table: holds the data sent from your device.
  • Device names table: holds the names of all the devices that have published data to our topic.

It is important to consider that the scalability of this service depends mainly on the storage required, the Read Capacity Units (RCU) and the Write Capacity Units (WCU). For this project, the provisioned throughput capacity is 8 RCU and 5 WCU. You can find more information regarding the provisioning capacity here.

Lambda

The Lambda service allows for triggering functions under specific circumstances. For this project, the lambda function will be connected to an API Gateway, and when a specific API call is made it will trigger the function.

The lambda function in this project responds to requests for the data stored in the DynamoDB tables. This allows the user to check the state of their plants as well as the evolution of the state of their plants over time.

API Gateway

The API Gateway service allows you to create and manage your APIs, and redirect the calls to the specific handler. The CloudFormation template creates a REST API which has 2 endpoints:

  • /plants: endpoint for all the plants/devices.
  • /plants/{id}: endpoint for a specific plant/device, with {id} being their name.

Each of the endpoints responds to a GET request, which is linked with the lambda function previously mentioned. Below you can see the diagram for the /plants endpoint when a GET request is issued:

S3

The S3 service allows for storing files and also has functionality for hosting static websites.

For our project the main purpose will be the latter, considering that we want to host our website on AWS. To do that, the CloudFormation template enables Static Website Hosting for the S3 bucket, using the index.html as the main entry point for the website. With this, you need to build the website first using node.

  1. Download the files for the website.
  2. Unzip the website project and open the .env file in your favorite editor.
  3. Paste in the URL for your API gateway. The URL can be found in AWS -> API Gateway -> <your API gateway name> -> Settings -> Default Endpoint.
  4. Install the dependencies: npm install (this requires npm to be installed).
  5. Build the project: npm run build.
  6. Upload the files in the build folder to the S3 bucket.

Your S3 bucket should look something like this after uploading the files for the website:

After that, you should be able to see the information displayed on the Bucket website endpoint (which can be found under <your-bucket-name> -> Properties -> Static Website Hosting).